# Setup NMDB scripts

# create NMDB config file
CONFIG=~/.nmdbrc
if [ -e $CONFIG ] ; then
  echo "$CONFIG already exists. Rename or delete it if you want to overwrite it!"
else
  cd && cat > $CONFIG <<EOF
[download]
username = READONLYUSER
password = readonlypasswd

[stat]
username = stat
password = supersecretpassword
longname = "Station"
EOF
fi

# directory for the NMDB scripts
cd && mkdir -p src/python/site-packages
cd src/python/site-packages

# get the source code
git clone https://code.google.com/p/nmdb/
# update the source code whenever a new version is out
git pull

# setup scripts in users bin directory which should be in PATH
cd && mkdir bin
cd bin
ln -s ~/src/python/site-packages/nmdb/bin/download.py
ln -s ~/src/python/site-packages/nmdb/bin/upload.py
ln -s ~/src/python/site-packages/nmdb/bin/station2sql.py
ln -s ~/src/python/site-packages/nmdb/bin/revise.py
ln -s ~/src/python/site-packages/nmdb/scripts/nmdb_revise.sh

# get a copy of the kiel script for real-time upload
sed s/kiel/stat/ < ~/src/python/site-packages/nmdb/scripts/nmdb_kiel.sh | sed s/KIEL/STAT/ > nmdb_stat.sh
chmod +x nmdb_stat.sh

# get a copy of the revise script
cd && cp ~/src/python/site-packages/nmdb/scripts/revise_batch.sh .

# directory for temporary files
cd && mkdir /var/tmp/nmdb
# directory for log files
cd && mkdir logs

